//
//  Test.swift
//  DataStructures
//
//  Created by Red App on 2018/6/13.
//  Copyright © 2018年 CEC-CESEC. All rights reserved.
//

import Foundation


func linklist() {
    var list = LinkedList<Int>()
    list.append(1)
}

func nodeTest() {
    let node1 = Node(value: 1)
    let node2 = Node(value: 2)
    let node3 = Node(value: 3)
    let node4 = Node(value: 14)
    
    node1.next = node2
    node2.next = node3
    node3.next = node4
    
    print(node1)
}


func queue() {
    var queue = QueueArray<String>()
    queue.enqueue("Ray")
    queue.enqueue("UK")
    queue.enqueue("China")
    queue.enqueue("Japan")
    queue.dequeue()
    queue.peek
    print(queue)
}

/// Swift 自定义集合类
func bagExtention() {
    var bag = Bag<Int>()
    
    bag.add(1)
    bag.add(2)
    bag.add(3)
    bag.add(3)
    bag.add(3)
    bag.add(3)
    
    var shoppingCart = Bag<String>()
    shoppingCart.add("Banana")
    shoppingCart.add("Orange", occurrences: 2)
    shoppingCart.add("Banana")
    shoppingCart.remove("Orange")
    
    print(shoppingCart)
    
    //bag.add(3, occurrences: 2)
    //bag.remove(3, occurrences: 2)
    
    
    print(bag.totalCount)
    print(bag.uniqueCount)
    
    let dataArray = ["Banana", "Orange", "Banana"]
    let dataDictionary = ["Banana": 2, "Orange": 1]
    let dataSet: Set = ["Banana", "Orange", "Banana"]
    
    //var arrayBag = Bag(dataArray)
    //precondition(arrayBag.contents == dataDictionary, "Expected arrayBag contents to match \(dataDictionary)")
    //
    //var dictionaryBag = Bag(dataDictionary)
    //precondition(dictionaryBag.contents == dataDictionary, "Expected dictionaryBag contents to match \(dataDictionary)")
    //
    //var setBag = Bag(dataSet)
    //precondition(setBag.contents == ["Banana": 1, "Orange": 1], "Expected setBag contents to match \(["Banana": 1, "Orange": 1])")
    
    var arrayLiteralBag: Bag = ["Banana", "Orange", "Banana"]
    //precondition(arrayLiteralBag.contents == dataDictionary, "Expected arrayLiteralBag contents to match \(dataDictionary)")
    //
    var dictionaryLiteralBag: Bag = ["Banana": 2, "Orange": 1]
    //precondition(dictionaryLiteralBag.contents == dataDictionary, "Expected dictionaryLiteralBag contents to match \(dataDictionary)")
}


/// 栈测试
func stackDemo() {
    var stack = Stack<Int>()
    stack.push(1)
    stack.push(2)
    stack.push(3)
    stack.push(4)
    stack.push(5)
    stack.push(6)
    
    print(stack)
    
    if let poppedElement = stack.pop() {
        assert(6 == poppedElement)
        print("Popped: \(poppedElement)")
    }
    
    
    var stack1: Stack = [12, 23, 34, 54, 6,5, 42, 423, 6456, 423]
    print(stack1)
}
